<?php

namespace frontend\models;

/**
 * @author  shuang
 * @date    2016-10-9 7:50:14
 * @version V1.0
 * @desc    
 */
use Yii;

/**
 * This is the model class for table "me_admin".
 *
 * @property integer $id
 * @property string $username
 * @property string $auth_key
 * @property string $password_hash
 * @property string $password_reset_token
 * @property string $phone
 * @property integer $status
 * @property string $email
 * @property integer $created_at
 * @property integer $updated_at
 */
class WB_User extends \yii\db\ActiveRecord {

    /**
     * @inheritdoc
     */
    public static function tableName() {
        return 'me_user';
    }

    public function scenarios() {
        return [
            'create' => ['username', 'phone', 'email', "authids", "password", "repassword"],
            'update' => ['phone', 'email', "authids"],
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules() {
        return [
        ];
    }

    /*
     * 设置表字段的中文描述
     * return array
     */

    /**
     * @inheritdoc
     */
    public function attributeLabels() {
        return [
            'id' => '管理员ID',
            'username' => '用户名称',
            'password' => '用户密码',
            "repassword" => "重复密码",
            'created_at' => '用户创建时间',
            'email' => '电子邮箱',
            'icon' => '用户图标',
            'phone' => '联系方式',
            'updated_at' => '更新时间',
        ];
    }

    public function getUserprofile() {
        return $this->hasOne(WB_UserProfile::className(), ['userid' => 'id']);
    }

    public function getUseraccount() {
        return $this->hasOne(WB_UserAccount::className(), ['userid' => 'id']);
    }

    public static function getuserbase(){
        return WB_User::find()->with(["useraccount","userprofile"])->where("id=".Yii::$app->user->id)->asArray()->one();
    }
}
